/*
 * bcti_dtaLog.h
 *
 *  Created on: 2010-12-31
 *      Author: li.zhaoping
 */

#ifndef BCTI_DTALOG_H_
#define BCTI_DTALOG_H_

#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include <sys/time.h>
#include <unistd.h>

#define CRAWLER_FLAG "[crawler]: "

#define ERR_(format, ...) do {\
								printf("\033[1;31m");\
								printf(CRAWLER_FLAG);\
								printf("[%s;%d]",__FILE__,__LINE__);\
								printf(format, ## __VA_ARGS__);\
								printf("\033[0m");\
						   }while(0)


#define WARN_(format, ...) do {\
								printf("\033[1;33m");\
								printf(CRAWLER_FLAG);\
								printf(format, ## __VA_ARGS__);\
								printf("\033[0m");\
						   }while(0)


#define INFO_(format, ...) do {\
								printf("\033[1;32m");\
								printf(CRAWLER_FLAG);\
								printf(format, ## __VA_ARGS__);\
								printf("\033[0m");\
						   }while(0)


#ifdef DEBUG
	#define DEBUG_(format, ...) do {\
									printf("\033[1;30m");\
									printf(CRAWLER_FLAG);\
									printf(format, ## __VA_ARGS__);\
									printf("\033[0m");\
							   }while(0)

#else
	#define DEBUG_(format, ...)

#endif

#ifdef DEBUG_TIME
#define LOG_TIME_(format, ...) do{\
										printf("\033[1;32m");\
										printf(CRAWLER_FLAG);\
										printf("time############");\
										printf(format, ## __VA_ARGS__);\
										struct timeval tv_now;\
										memset(&tv_now,0,sizeof(struct timeval));\
										gettimeofday(&tv_now,NULL);\
										printf("[%lds, %ldms] \n",tv_now.tv_sec,tv_now.tv_usec);\
										printf("\033[0m");\
									}while(0)
#else
	#define LOG_TIME_(format, ...)
#endif


#ifdef DEBUG_MEM
#define LOG_MEMINFO(tipStr) do{\
											char cmdStr[1024];\
											memset(cmdStr,0,sizeof(cmdStr));\
											sprintf(cmdStr,"echo [%s] >> ./dtaMem.log",tipStr);\
											int tttttt = system(cmdStr);\
											memset(cmdStr,0,sizeof(cmdStr));\
											sprintf(cmdStr,"cat /proc/%d/status | grep VmRSS >> ./dtaMem.log",getpid());\
											tttttt = system(cmdStr);\
											}while(0);
#else
	#define LOG_MEMINFO(tipStr)
#endif



#endif /* BCTI_DTALOG_H_ */
